package org.example.socket网络编程.TCP;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPFileServerDemo {
    public static void main(String[] args) throws IOException {
        // 创建服务
        ServerSocket serverSocket = new ServerSocket(10000);
        // 监听客户端
        Socket socket = serverSocket.accept();
        // 获取输入流
        InputStream inputStream = socket.getInputStream();
        // 文件输出
        FileOutputStream fileOutputStream = new FileOutputStream("out.jpg");
        byte[] buffer = new byte[1024];
        int len = 0;
        while ( (len = inputStream.read(buffer)) != -1 ){
            fileOutputStream.write(buffer, 0, len);
        }
        socket.close();
        serverSocket.close();
        inputStream.close();
        fileOutputStream.close();


    }
}
